import * as THREE from 'three'
import Sizes from './Sizes';
import Camera from './Camera'
import Renderer from './Renderer';
import Time from './Time';
import Cube from './Cube';
import Utils from './Utils';
import CssRender from './CssRender';
// 添加场景组
import Group from '../group/Group';
// 单例 由于THREE.js中各种类互有引用 因此创建一个统一的类来管理它们
export default class Experience {
    static instance;
    constructor(canvas, outBox) {

        if (Experience.instance) return Experience.instance;
        Experience.instance = this;
        this.outBox = outBox;
        this.canvas = canvas;
        this.scene = new THREE.Scene()
        this.sizes = new Sizes();
        this.camera = new Camera();
        this.time = new Time();
        this.renderer = new Renderer();
        this.utils = new Utils();
        this.cssRender = new CssRender();
        // 场地
        this.cube = new Cube();
        // 所有场景
        this.group = new Group();

        this.time.on('update', () => {
            this.update();
        })
        this.sizes.on('resize', () => {
            this.resize();
        })
    }
    update() {
        // console.log(this.time.delta);
        this.camera.update();
        this.renderer.update();
        this.cssRender.update();
        this.group.line.updateLine2();
        // this.group.svg.update();
    }
    resize() {
        this.camera.resize();
        this.renderer.resize();
        this.cssRender.resize();
    }
    destroy() {
        Experience.instance = null;
    }
}